package com.gdust.hzx.product.controller;

import com.gdust.hzx.model.entity.product.Category;
import com.gdust.hzx.model.entity.product.ProductSku;
import com.gdust.hzx.model.vo.common.Result;
import com.gdust.hzx.model.vo.common.ResultCodeEnum;
import com.gdust.hzx.model.vo.h5.IndexVo;
import com.gdust.hzx.product.service.CategoryService;
import com.gdust.hzx.product.service.ProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName: IndexController
 * Package: com.gdust.hzx.product.controller
 * Description:首页接口管理控制层
 *
 * @Author syun
 * @Create 2024/12/25 20:11
 * @Version 1.0
 */
@Tag(name = "首页接口管理")
@RestController
@RequestMapping(value="/api/product/index")
//@CrossOrigin //跨域
public class IndexController {
    //注入商品分类表的service
    @Autowired
    private CategoryService categoryService;

    //注入产品表的service
    @Autowired
    private ProductService productService;


    /**
     * 获取首页数据
     * 补充：spu: 商品名称或通用属性（如品牌、型号等）
     *      sku: 商品的具体参数（如颜色、规格等）
     * @return
     */
//    @Log(title = "获取首页数据",businessType = 0,operatorType = OperatorType.MANAGE)
    @Operation(summary = "获取首页数据")
    @GetMapping
    public Result index(){
        //1.查询所有一级分类
        List<Category> categoryList = categoryService.selectOneCategory();

        //2.根据销量排序，获取前10条记录
        List<ProductSku> productSkuList = productService.selectProductSkuBySale();

        //3.封装数据到vo对象里面
        IndexVo indexVo = new IndexVo();//新建一个indexVo对象，用于存储获取后的数据
        indexVo.setCategoryList(categoryList);
        indexVo.setProductSkuList(productSkuList);
        return Result.build(indexVo, ResultCodeEnum.SUCCESS);
    }


}
